package cn.devzyh.oms.coms.flow.service.impl;

import cn.devzyh.oms.coms.api.flow.entity.Edge;
import cn.devzyh.oms.coms.flow.executor.FlowExecutor;
import cn.devzyh.oms.coms.flow.mapper.EdgeMapper;
import cn.devzyh.oms.coms.flow.service.EdgeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EdgeServiceImpl extends ServiceImpl<EdgeMapper, Edge> implements EdgeService {

	@Override
	public List<Edge> listEdges(Long flowId, Long startNodeId) {
		LambdaQueryWrapper<Edge> wrapper = Wrappers.lambdaQuery();
		wrapper.eq(Edge::getFlowId, flowId);
		wrapper.eq(Edge::getStartNodeId, startNodeId == null ? FlowExecutor.START_NODE_ID : startNodeId);
		wrapper.orderByAsc(Edge::getExpression);
		return list(wrapper);
	}

}